Ext.define('Admin.view.orderManage.OrderManageViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.orderManage',
	onClickPrintExcel: function (btn) {
		var grid = btn.up('gridpanel');
		var selModel = grid.getSelectionModel();
		if (selModel.hasSelection()) {
			Ext.Msg.confirm("提示", "确定要导出吗？", function (button) {
				if (button == "yes") {
					var selected = selModel.getSelection();
					var selectOrderIds = [];
					Ext.each(selected, function (item) {
						selectOrderIds.push(item.data.orderId);
					})
					Ext.Ajax.request({
						method: 'post',
						defaultHeaders: {
							"X-CSRF-TOKEN": document.getElementsByTagName('meta')['_csrf'].content
						}, 
						url : 'order/printExcel', 
						params : { 
							orderIds :selectOrderIds
						},
						success: function(response, options) {
							var json = Ext.util.JSON.decode(response.responseText);
							if(json.success){
								Ext.Msg.alert('操作成功', json.msg, function() {
									grid.getStore().reload();
								});
							}else{
								 Ext.Msg.alert('操作失败', json.msg);
							}
						}
					});

				}
			});
		}
		else {
			Ext.Msg.alert("错误", "没有任何行被选中，无法进行导出数据操作！");
		}
    },
	orderGridPanelQuickSearch:function(btn){
		var searchField = this.lookupReference('orderGridSearchField').getValue();
		var searchText = this.lookupReference('orderGridSearchText').getValue();
		var startTime = Ext.util.Format.date(this.lookupReference('startTime').getValue(),'Y-m-d');
		var endTime = Ext.util.Format.date(this.lookupReference('endTime').getValue(),'Y-m-d');
		var store = Ext.getCmp('orderManageGrid').getStore();//对应grid的id属性
		//1.清空所有QueryDTO中的查询条件
		Ext.apply(store.proxy.extraParams, {
			departmentName:'',
			userName:'',
			startTime:'',
			endTime:''
		}); 
		//2.按照所选字段进行查询参数（条件）的扩展
		if(searchField=='departmentName'){
			Ext.apply(store.proxy.extraParams, {
				departmentName:searchText
			});  
		}
		if(searchField=='userName'){
			Ext.apply(store.proxy.extraParams, {
				userName:searchText
			});  
		}
		if(searchField=='approvalTime'){
			Ext.apply(store.proxy.extraParams, {
				startTime:startTime,
				endTime:endTime,
			}); 
			 
		}
		store.load({url:'order/find',params: {start:0,limit:25,page:1}}); 
	}
});